package com.zcf.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zcf.common.json.Body;
import com.zcf.pojo.Money;
import com.zcf.vo.out.LayuiJson;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jj
 * @date 2019/11/12 9:10
 */
public class MoneyServiceImpl {

    /**
    * @description :查询主码
    * @date : 2019/11/12 9:13
    * @author : jj
    */
    public Body get(Integer gameType,Integer roomGrade){
        Money money=new Money();
        Money money1 = money.selectOne(new EntityWrapper().eq("game_type", gameType).eq("room_grade",roomGrade));
        List<Integer> list = new ArrayList<>();
        list.add(money1.getMoney1());
        list.add(money1.getMoney2());
        list.add(money1.getMoney3());
        list.add(money1.getMoney4());
        list.add(money1.getMoney5());
        list.add(money1.getMoney6());
        return money1!=null?Body.newInstance(list):Body.BODY_470;
    }


    /**
     * @description :查询主码
     * @date : 2019/11/12 9:13
     * @author : jj
     */
    public LayuiJson findList(Integer gameType){
        LayuiJson lj=new LayuiJson();
        Money money=new Money();
        List<Money> moneyList = money.selectList(new EntityWrapper().eq("game_type", gameType));
        if(moneyList.size()>0){
            lj.setCode(0);
            lj.setCode(0);
            lj.setCount(moneyList.size());
            lj.setMsg("yes");
            lj.setData(moneyList);
            return lj;
        }
        lj.setCode(1);
        lj.setCount(0);
        lj.setMsg("no data");
        lj.setData(null);
        return lj;
    }


    /**
     * @description :修改相关信息
     * @date : 2019/11/12 9:13
     * @author : jj
     */
    @Transactional(rollbackFor = Exception.class)
    public Body update(Money money) { return  money.updateById() ?  Body.BODY_200 : Body.BODY_451; }
}
